package com.easy.service.impl;

import com.easy.bean.Product;
import com.easy.mapper.ProductDao;
import com.easy.service.ProductService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    ProductDao productDao;

    @Override
    public Product add(Product product) {
        productDao.add(product);
        return productDao.one(product.getId());
    }

    @Override
    public int del(Integer id) {
        return productDao.del(id);
    }

    @Override
    public Product edit(Product product) {
        productDao.edit(product);
        return productDao.one(product.getId());
    }

    @Override
    public List<Product> all(String name, String category) {
        return productDao.all(name, category);
    }

    @Override
    public Product one(Integer id) {
        return productDao.one(id);
    }

    @Override
    public void page(Page page, Product product) {
        int count = productDao.pageCount(product);
        Object data = productDao.page(page, product);
        page.setCount(count);
        page.setData(data);
    }
}
